<?php

require_once("Accountant.class.php");
require_once("exceptions/AppExceptions.class.php");

class AllFileStateAccountant extends Accountant {

	private $detail = false;
	/**
	 * 未完成的材料代码的数量的数组
	 *
	 * @var array
	 */
	private $unFinishedCount = array();

	/**
	 * 完成的材料代码的数量的数组
	 *
	 * @var array
	 */
	private $finishedCount = array();

	/**
	 * 文件中distinct的材料代码的数量的数组
	 *
	 * @var array
	 */
	private $distinctCertificationNumberCount = array();

	/**
	 * 上传时间的数组
	 *
	 * @var array
	 */
	private $uploadTime = array();

	/**
	 * 文件名的数组
	 *
	 * @var array
	 */
	private $filename = array();


	/**
	 * 构造函数
	 *
	 * @param boolean $_detail
	 */
	public function __construct($_detail = false){
		$this->detail = $_detail;
		$this->sql = "select filename, uploadTime, count(distinct sampleBatch,orderNumber,orderSubitemNumber) as distinctCertificationNumberCount
		from little_main
		group by filename
		order by filename asc, uploadTime desc;";
	}

	/**
	 * 执行查询命令，并整理查询的结果
	 *
	 */
	public function execute(){
		$this->result = DB::query($this->sql);
		if($this->result == false){
			return;
		}
		if($this->detail){
			while($row = $this->result->fetch_assoc()){
				array_push($this->filename, $row['filename']);
				array_push($this->uploadTime, $row['uploadTime']);
				array_push($this->distinctCertificationNumberCount, intval($row['distinctCertificationNumberCount']) );
				array_push($this->finishedCount, intval($row['finishedCount']) );
				array_push($this->unFinishedCount, intval($row['distinctCertificationNumberCount']) - intval($row['finishedCount']) );
			}
		}else{
			while($row = $this->result->fetch_assoc()){
				array_push($this->filename, $row['filename']);
				array_push($this->uploadTime, $row['uploadTime']);
				array_push($this->distinctCertificationNumberCount, intval($row['distinctCertificationNumberCount']) );
			}
		}
	}


	public function getFilename(){
		return $this->filename;
	}
	public function getUploadTime(){
		return $this->uploadTime;
	}
	public function getDistinctCertificationNumberCount(){
		return $this->distinctCertificationNumberCount;
	}
	public function getFinishedCount(){
		return $this->finishedCount;
	}
	public function getUnFinishedCount(){
		return $this->unFinishedCount;
	}


}
?>